#ifndef _H_VARIANT
#define _H_VARIANT

#include <iostream>
#include <string>

using namespace std;

#define VAR_UNDEF       0
#define VAR_UINT        1
#define VAR_INT         2
#define VAR_USHORT      3
#define VAR_SHORT       4
#define VAR_ULONG       5
#define VAR_LONG        6
#define VAR_BYTE        7
#define VAR_CHAR        8
#define VAR_FLOAT       9
#define VAR_DOUBLE      10
#define VAR_STRING      11
#define VAR_DATA        12

class data_chunk{
    public:
        unsigned int    size;
        unsigned char*  data;

        data_chunk();
        data_chunk(unsigned char*,unsigned int);
        data_chunk(data_chunk*);
        ~data_chunk();

        void copy(data_chunk*);

        void exportDC(FILE*);
        void importDC(FILE*);
};

class variant{

    protected:
        unsigned char   byType;
        union{
            unsigned int    uiVal;
            int             iVal;
            unsigned short  unVal;
            short           nVal;
            unsigned long   ulVal;
            long            lVal;
            unsigned char   byVal;
            char            cVal;
            float           fVal;
            double          dVal;
            char*           pszVal;
            data_chunk*     chunkVal;
        }uVal;

    public:
        variant();
        ~variant();

        void copy(variant*);

        void exportVariant(FILE*);
        void importVariant(FILE*);

        void setUInt(unsigned int);
        void setInt(int);
        void setUShort(unsigned short);
        void setShort(short);
        void setULong(unsigned long);
        void setLong(unsigned long);
        void setByte(unsigned char);
        void setChar(char);
        void setFloat(float);
        void setDouble(double);
        void setString(char*);
        void setData(data_chunk*);
        void clear();

        unsigned char getType();

        unsigned int    getUInt();
        int             getInt();
        unsigned short  getUShort();
        short           getShort();
        unsigned long   getULong();
        long            getLong();
        unsigned char   getByte();
        char            getChar();
        float           getFloat();
        double          getDouble();
        char*           getString();
        void            getString(char*);
        unsigned int    getStringLen();
        data_chunk*     getData();
        void            getData(data_chunk*);

        static const char* typeToString(unsigned char);
        static const char* typeToShortString(unsigned char);

        void fromStrings(char*,char*);

        string toString();

};

#endif
